require 'download'

# TODO Determine which platform is present and determine the best default cache location for each platform.

BaseUrl = 'http://www.imdb.com/'

$CacheFolder = nil

# TODO Make this function platform independant ^_^
def DetermineCacheLocation()
    processor, platform, *rest = RUBY_PLATFORM.split("-")
    if platform == 'mswin32' then
        $CacheFolder = ENV['TEMP']
    else
        $CacheFolder = ENV['TEMP']
    end
end

class Cache

    private

    CacheFolder = 'cache'

    attr_accessor :path
    
    # Determine if the cache folder exists.
    def CacheFolderExists()
        return File.exist(CacheFolder)
    end

    public

    # Constructor.
    def initialize(uri)
        path = File.join(CacheFolder, uri.host, uri.path).chop()
        #puts path.ch
        puts CacheFolderExists()
        #
    end

end

#$CacheFolder = 'cache'
#$BaseUrl = 'http://www.imdb.com/'

# Determine if file is in cache.
def cached(location)
    return false
end

# Download file into cache.
def download(location)
    #
end

# Read file from cache.
def read(location)
    #
end

# Retrieve file from cache.
def retrieve(location)
    # If not cached then download into cache first.
    # then return file from cache.
end

cache = Cache.new(URI.parse('http://www.imdb.com/title/tt0247082/'))

#retrieve('title/tt0247082')
#a = URI.parse('http://www.imdb.com/title/tt0247082/').host
#b = URI.parse('http://www.imdb.com/title/tt0247082/').path
#puts File.join(a, b)

#$data = Net::HTTP.get_response(URI.parse('http://www.imdb.com/title/tt0247082/')).body
#$values = Hash.new()
